ValueFolderTemp='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsJournal\';
ValueFolderTemp2='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsEditor\';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
ValueCutoff=1.25;
VecFigure=[];
VecFigure2=[];
VecFigure3=[];
VecFigure5=[];
nEditor11=0;
nEditor21=0;
nEditor12=0;
nEditor22=0;
VecJournals11=[];
VecJournals21=[];
VecJournals12=[];
VecJournals22=[];
VecResultsTemp6=[];
VecResultsCoAuthors=[];
VecResultsEditorAfter=[];
VecResultsEditorBefore=[];
VecResultsEditorTemp2=[];
VecResultsEditorsJournalBefore=[14 4;43 33;64 12;103 28;132 21;149 28;199 4;282 33;241 2];
for n1=1:323
    n1
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    n5Temp5=0;
    if size(ValueTemp,1)==1&&n1~=11
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            ValueJournal=VecValueEditor{n1,11};
            ValueTempBefore=find(VecResultsEditorsJournalBefore(:,1)==n1);
            if size(ValueTempBefore,1)==1
                n3=VecResultsEditorsJournalBefore(ValueTempBefore,2);
            else
                n3=1;
                TestTemp=0;
                while n3<=size(VecValueJournal,1)&&TestTemp==0
                    if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                        TestTemp=1;
                    else
                        n3=n3+1;
                    end
                end
            end
%             ValueFileTemp4=dir([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
%             if size(ValueFileTemp4,1)==1
                load([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
                load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
                VecValueTemp24=[];
                VecValueTemp25=[];
                VecValueTemp24Temp=[];
                VecValueTemp25Temp=[];
                ValueTime=clock();
                for n2=1:33
                    if n2==n3
                        eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m2;']);
%                         eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m2Filtered;']); % robustness analysis for the first group of co-authors
                        VecValueTemp22=VecValueTemp';
                        eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m2;']);
%                         eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m2Filtered;']); % robustness analysis for the first group of co-authors
                        VecValueTemp23=VecValueTemp';
                    else
                        eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1;']);
%                         eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1Filtered;']); % robustness analysis for the first group of co-authors
                        if size(VecValueTemp24,2)==0&&size(VecValueTemp,2)>=1
                            VecValueTemp24=VecValueTemp;
                            eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                             eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                            VecValueTemp24Temp=VecValueTemp2;
                        else
                            if size(VecValueTemp,2)>=1
                                eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                                 eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                                for n4=1:size(VecValueTemp2,2)
                                    n5=1;
                                    TestTemp=0;
                                    while TestTemp==0&&n5<=size(VecValueTemp24Temp,2)
                                        if size(VecValueTemp24Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp24Temp{1,n5}-VecValueTemp2{1,n4}))==0
                                            TestTemp=1;
                                        else
                                            n5=n5+1;
                                        end
                                    end
                                    if n5<=size(VecValueTemp24Temp,2)
                                        VecValueTemp24(:,n5)=VecValueTemp24(:,n5)+VecValueTemp(:,n4);
                                    else
                                        VecValueTemp24(:,n5)=VecValueTemp(:,n4);
                                        VecValueTemp24Temp(1,n5)={VecValueTemp2{1,n4}};
                                    end
                                end
                                if size(VecValueTemp2,2)>0
                                    n5Temp5=n5Temp5+1;
                                end
                            end
                        end
                    end
%                     eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m1;']);
%                     if size(VecValueTemp25,2)==0&&size(VecValueTemp,2)>=1
%                         VecValueTemp25=VecValueTemp;
%                         eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                         VecValueTemp25Temp=VecValueTemp2;
%                     else
%                         if size(VecValueTemp,2)>=1
%                             eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                             for n4=1:size(VecValueTemp2,2)
%                                 n5=1;
%                                 TestTemp=0;
%                                 while TestTemp==0&&n5<=size(VecValueTemp25Temp,2)
%                                     if size(VecValueTemp25Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp25Temp{1,n5}-VecValueTemp2{1,n4}))==0
%                                         TestTemp=1;
%                                     else
%                                         n5=n5+1;
%                                     end
%                                 end
%                                 if n5<=size(VecValueTemp25Temp,2)
%                                     VecValueTemp25(:,n5)=VecValueTemp25(:,n5)+VecValueTemp(:,n4);
%                                 else
%                                     VecValueTemp25(:,n5)=VecValueTemp(:,n4);
%                                     VecValueTemp25Temp(1,n5)={VecValueTemp2{1,n4}};
%                                 end
%                             end
%                         end
%                     end
                end
                ValueTime2=clock();
                ValueTimeTemp=(ValueTime2(1,4)-ValueTime(1,4))*60+ValueTime2(1,5)-ValueTime(1,5);
                VecValueTemp24=VecValueTemp24';
                VecValueTemp25=VecValueTemp25';
                if size(VecValueTemp22,1)>=1
                    ValueTemp5=find(isnan(VecValueTemp22(:,2))==0);
                    ValueTemp5=size(ValueTemp5,1);
                else
                    ValueTemp5=0;
                end
                if size(VecValueTemp24,1)>=1
                    ValueTemp4=find(isnan(VecValueTemp24(:,2))==0);
                    VecResultsCoAuthors=[VecResultsCoAuthors;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                else
                    VecResultsCoAuthors=[VecResultsCoAuthors;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                end
                if VecResultsEditor(1,16)<=3.61
%                 if VecResultsEditor(1,16)<=11.77&&VecResultsEditor(1,16)>=5.61
%                 if VecResultsEditor(1,16)<=11.77
                    ValueGroupEditor=1;
%                     nEditor1=nEditor1+1;
                else
                    if VecResultsEditor(1,16)>=5.61&&VecResultsEditor(1,16)<=9.24
%                     if VecResultsEditor(1,16)>=13.77
%                     if VecResultsEditor(1,16)>=5.61 % Robustness analysis for the inclusion of editors
                        ValueGroupEditor=2;
%                         nEditor2=nEditor2+2;
                    else
                        ValueGroupEditor=0;
                    end
                end
                if n3==32
                    ValueGroupJournal=1;
                    ValueGroupJournalTemp=1;
                else
                    if n3==33
                        ValueGroupJournal=3;
                        ValueGroupJournalTemp=1;
                    else
                        ValueGroupJournal=2;
                        ValueGroupJournalTemp=2;
                    end
                end
%                 if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1
                    if size(VecValueEditor{n1,22},2)<=3||size(ValueTempBefore,1)==1
                        % First column of VecValueTemp22 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                        if ValueGroupEditor>0
                            if ValueGroupEditor==1
                                nEditor11=nEditor11+1;
                                VecJournals11=[VecJournals11;n1]; 
                                if n1~=125&&n1~=151&&n1~=303
                                    VecResultsEditorAfter=[VecResultsEditorAfter;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                                else
                                    VecResultsEditorTemp2=[VecResultsEditorTemp2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                                end
                                VecResultsEditorAfter=[VecResultsEditorAfter;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                            else
                                nEditor21=nEditor21+1;
                                VecJournals21=[VecJournals21;n1];
                                if n1~=125&&n1~=151&&n1~=303
                                    VecResultsEditorBefore=[VecResultsEditorBefore;VecResultsEditor(1,1) VecResultsEditor(1,16)-5.61 VecResultsEditor(1,27) ValueGroupJournalTemp];
                                else
                                    VecResultsEditorTemp2=[VecResultsEditorTemp2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                                end
                            end
                            VecFigure3=[VecFigure3;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1) ValueGroupEditor*ones(size(VecValueTemp22,1),1) ValueGroupJournal*ones(size(VecValueTemp22,1),1)];
                            VecFigure3=[VecFigure3;VecValueTemp23 VecValueTemp23(:,1)+VecValueTemp23(:,2) VecValueTemp23(:,1)-VecValueTemp23(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp23,1),1) n3*ones(size(VecValueTemp23,1),1) 2*ones(size(VecValueTemp23,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp23,1),1) n1*ones(size(VecValueTemp23,1),1) ValueGroupEditor*ones(size(VecValueTemp23,1),1) ValueGroupJournal*ones(size(VecValueTemp23,1),1)];
                            ValueTemp=find(VecValueTemp22(:,1)==0&VecValueTemp22(:,2)>0);
                            ValueTemp2=find(VecValueTemp23(:,1)==0&VecValueTemp23(:,2)>0);
                            VecFigure5=[VecFigure5;size(ValueTemp,1) size(VecValueTemp22,1) size(ValueTemp2,1) size(VecValueTemp23,1)];
                        else
                            VecResultsEditorTemp2=[VecResultsEditorTemp2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                        end
                    else
                        VecResultsEditorTemp2=[VecResultsEditorTemp2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                    end
                else
                    VecResultsEditorTemp2=[VecResultsEditorTemp2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueGroupJournalTemp];
                end
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1
                    if size(VecValueEditor{n1,22},2)<=3||size(ValueTempBefore,1)==1
                        % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                        if ValueGroupEditor>0
                            if ValueGroupEditor==1
                                nEditor12=nEditor12+1;
                                VecJournals12=[VecJournals12;n1];
                            else
                                nEditor22=nEditor22+1;
                                VecJournals22=[VecJournals22;n1];
                            end
                            VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1) ValueGroupEditor*ones(size(VecValueTemp22,1),1) ValueGroupJournal*ones(size(VecValueTemp22,1),1)];
        %                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                            VecFigure2=[VecFigure2;VecValueTemp24 VecValueTemp24(:,1)+VecValueTemp24(:,2) VecValueTemp24(:,1)-VecValueTemp24(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1) ValueGroupEditor*ones(size(VecValueTemp24,1),1) ValueGroupJournal*ones(size(VecValueTemp24,1),1)];
                        end
                        VecResultsTemp6=[VecResultsTemp6;VecResultsEditor(1,16)];
                    end
                end
%                 % Robustness analysis (we average over the number of Nature journals)
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&n5Temp5>0
%                     % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
%                     VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
% %                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp5 VecValueTemp24(:,1)+VecValueTemp24(:,2) (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp5 VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                 end
%             end
        end
    end
end

VecResultsEditorTemp=[];
ValueTemp=find(VecResultsEditorAfter(:,1)==44);
VecResultsEditorAfter(ValueTemp,:)=[];
ValueTemp=find(VecResultsEditorBefore(:,1)==44);
VecResultsEditorBefore(ValueTemp,:)=[];
for n1=1:3
    ValueTemp=find(isnan(VecResultsEditorAfter(:,n1))==0);
    ValueTemp2=find(isnan(VecResultsEditorBefore(:,n1))==0);
    [ValueResults,ValueResults2]=ttest2(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
    [ValueResults3,ValueResults4]=ranksum(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
    VecResultsEditorTemp=[VecResultsEditorTemp;mean(VecResultsEditorAfter(ValueTemp,n1)) sqrt(var(VecResultsEditorAfter(ValueTemp,n1))) median(VecResultsEditorAfter(ValueTemp,n1)) quantile(VecResultsEditorAfter(ValueTemp,n1),0.25) quantile(VecResultsEditorAfter(ValueTemp,n1),0.75) mean(VecResultsEditorBefore(ValueTemp2,n1)) sqrt(var(VecResultsEditorBefore(ValueTemp2,n1))) median(VecResultsEditorBefore(ValueTemp2,n1)) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.25) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.75) ValueResults2 ValueResults3 size(ValueTemp,1) size(ValueTemp2,1)];
end
ValueTemp=find(VecResultsEditorAfter(:,4)==1);
ValueTemp2=find(VecResultsEditorBefore(:,4)==1);
[ValueResults,ValueResults2,stats]=fishertest([size(ValueTemp,1) size(ValueTemp2,1);size(VecResultsEditorAfter,1)-size(ValueTemp,1) size(VecResultsEditorBefore,1)-size(ValueTemp2,1)])

VecResultsEditorAfter=[VecResultsEditorAfter;VecResultsEditorBefore];
VecResultsEditorBefore=VecResultsEditorTemp2;
for n1=1:3
    ValueTemp=find(isnan(VecResultsEditorAfter(:,n1))==0);
    ValueTemp2=find(isnan(VecResultsEditorBefore(:,n1))==0);
    [ValueResults,ValueResults2]=ttest2(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
    [ValueResults3,ValueResults4]=ranksum(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
    VecResultsEditorTemp=[VecResultsEditorTemp;mean(VecResultsEditorAfter(ValueTemp,n1)) sqrt(var(VecResultsEditorAfter(ValueTemp,n1))) median(VecResultsEditorAfter(ValueTemp,n1)) quantile(VecResultsEditorAfter(ValueTemp,n1),0.25) quantile(VecResultsEditorAfter(ValueTemp,n1),0.75) mean(VecResultsEditorBefore(ValueTemp2,n1)) sqrt(var(VecResultsEditorBefore(ValueTemp2,n1))) median(VecResultsEditorBefore(ValueTemp2,n1)) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.25) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.75) ValueResults2 ValueResults3 size(ValueTemp,1) size(ValueTemp2,1)];
end
ValueTemp=find(VecResultsEditorAfter(:,4)==1);
ValueTemp2=find(VecResultsEditorBefore(:,4)==1);
[ValueResults,ValueResults2,stats]=fishertest([size(ValueTemp,1) size(ValueTemp2,1);size(VecResultsEditorAfter,1)-size(ValueTemp,1) size(VecResultsEditorBefore,1)-size(ValueTemp2,1)])



% VecFigure4=VecFigure;
% VecFigure=VecFigure2;
% VecFigure=VecFigureTemp;
% VecFigureTemp=VecFigure;
VecFigure=VecFigure3;
ValueTemp=find(VecFigure(:,3)==0);
% ValueTemp=find(VecFigure(:,3)>8);
VecFigure(ValueTemp,:)=[];
ValueTemp=find(VecFigure(:,11)==125); % This editor has too many co-authors when using the threshold average+3*SD without the algorithm to remove homonyms (the algorithm does not converge to a non empty array)
VecFigure(ValueTemp,:)=[];
ValueTemp=find(VecFigure(:,11)==151); % This editor has too many co-authors when using the threshold average+3*SD without the algorithm to remove homonyms (the algorithm does not converge to a non empty array)
VecFigure(ValueTemp,:)=[];
ValueTemp=find(VecFigure(:,11)==303); % This editor has too many co-authors when using the threshold average+3*SD without the algorithm to remove homonyms (the algorithm does not converge to a non empty array)
VecFigure(ValueTemp,:)=[];
ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<=5*sqrt(var(VecFigure(:,3))));
% ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<=3*sqrt(var(VecFigure(:,3)))); % Robustness analysis for the threshold used to remove homonyms among authors
% ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<=4*sqrt(var(VecFigure(:,3)))); % Robustness analysis for the threshold used to remove homonyms among authors
% ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<=6*sqrt(var(VecFigure(:,3)))); % Robustness analysis for the threshold used to remove homonyms among authors
% ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<=7*sqrt(var(VecFigure(:,3)))); % Robustness analysis for the threshold used to remove homonyms among authors
VecFigure=VecFigure(ValueTemp,:);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,3);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,4);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,3,3); % Robustness analysis for the threshold used to remove homonyms 
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,4,3); % Robustness analysis for the threshold used to remove homonyms
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,6,3); % Robustness analysis for the threshold used to remove homonyms
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,7,3); % Robustness analysis for the threshold used to remove homonyms
% VecFigure=ValueTemp;
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResults=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResults
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==1
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
VecValueTemp5=repmat('C',size(VecFigure,1),1); % Editors who arrived after the launch of the editorial policy
ValueTemp=find(VecFigure(:,12)==2);
VecValueTemp5(ValueTemp,1)=repmat('D',size(ValueTemp,1),1); % Editors who arrived before the launch of the editorial policy
VecValueTemp6=repmat('M',size(VecFigure,1),1); % Specilized Nature journals
ValueTemp=find(VecFigure(:,13)==1);
VecValueTemp6(ValueTemp,1)=repmat('L',size(ValueTemp,1),1); % Nature
ValueTemp=find(VecFigure(:,13)==3);
VecValueTemp6(ValueTemp,1)=repmat('L',size(ValueTemp,1),1); % Nature Communications
VecValueTemp5=[VecValueTemp5(9623:end,:);VecValueTemp5(1:9622,:)]; % If commented, results are for authors who arrived before
VecValueTemp=[VecValueTemp(9623:end,:);VecValueTemp(1:9622,:)]; % If commented, results are for authors who arrived before
VecFigure=[VecFigure(9623:end,:);VecFigure(1:9622,:)]; % If commented, results are for authors who arrived before
% VecValueTemp5=[VecValueTemp5(9624:end,:);VecValueTemp5(1:9623,:)]; % If commented, results are for authors who arrived before
% VecValueTemp=[VecValueTemp(9624:end,:);VecValueTemp(1:9623,:)]; % If commented, results are for authors who arrived before
% VecFigure=[VecFigure(9624:end,:);VecFigure(1:9623,:)]; % If commented, results are for authors who arrived before
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel1=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],[VecValueTemp5;VecValueTemp5],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor','Time'});
% ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time+(1|Editor)','FitMethod','REML');
% % ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+CategoryAuthor*Time+CategoryArticle*Time+(1|Editor)','FitMethod','REML');
% VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],[VecValueTemp5;VecValueTemp5],[VecValueTemp6;VecValueTemp6],[VecFigure(:,7);VecFigure(:,7)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor','Time','Journal','Research'});
% ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time+(1|Editor)','FitMethod','REML');
% VecValueTemp4=table(VecFigure(:,4),VecValueTemp,repmat('A',size(VecFigure,1),1),VecFigure(:,11),VecValueTemp5,'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor','Time'});
% ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Time+(1|Editor)','FitMethod','REML');
VecValueTemp4=table(VecFigure(:,1)-VecFigure(:,2),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,2),VecFigure(:,11),VecValueTemp5,'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','ArticlesBefore','Editor','Time'});
ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Time+ArticlesBefore+(1|Editor)','FitMethod','REML'); % Mod�le pour l'article pour VecFigure3

return
ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time+CategoryAuthor*CategoryArticle*Research+(1|Editor)','FitMethod','REML'); % Robustness analysis adjusting ofr the research experience of the editors
% % Model for testing if there is a difference between journals with different reputation
% ValueResultsModel1Temp6=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time*Journal+(1|Editor)','FitMethod','REML');
VecValueTemp4=table(VecFigure(:,2)-VecFigure(:,1),VecValueTemp,VecFigure(:,11),VecValueTemp5,VecValueTemp6,VecFigure(:,7),'VariableNames',{'Articles','CategoryAuthor','Editor','Time','Journal','Research'});
ValueResultsModel1Temp21=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Research*Time+(1|Editor)','FitMethod','REML');
% ValueResultsModel1Temp21=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Time+Research*Time+(1|Editor)','FitMethod','REML');
% ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+CategoryAuthor*Time+CategoryArticle*Time+(1|Editor)','FitMethod','REML');
VecFigureTemp=VecFigure;
ValueTemp=find(VecFigureTemp(:,1)>=1);
VecFigureTemp(ValueTemp,1)=ones(size(ValueTemp,1),1);
% We keep only authors
ValueTemp=find(VecFigureTemp(:,2)>=1);
VecFigureTemp=VecFigureTemp(ValueTemp,:);
VecValueTemp=VecValueTemp(ValueTemp,:);
VecValueTemp5=VecValueTemp5(ValueTemp,:);
VecValueTemp6=VecValueTemp6(ValueTemp,:);
% VecValueTemp5=[VecValueTemp5(4:end,:);VecValueTemp5(1:3,:)]; % If commented, results are for authors who arrived before
% VecValueTemp=[VecValueTemp(4:end,:);VecValueTemp(1:3,:)]; % If commented, results are for authors who arrived before
% VecFigureTemp=[VecFigureTemp(4:end,:);VecFigureTemp(1:3,:)]; % If commented, results are for authors who arrived before
VecValueTemp4=table(VecFigureTemp(:,1),VecValueTemp,VecFigureTemp(:,2),VecFigureTemp(:,11),VecValueTemp5,VecValueTemp6,'VariableNames',{'ArticlesAfter','CategoryAuthor','ArticlesBefore','Editor','Time','Journal'});
ValueResultsModel1Temp3=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*Time+ArticlesBefore*Time+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');

return
% ValueResultsModel1Temp4=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*ArticlesBefore*Time*Journal+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');
% ValueResultsModel1Temp5=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*ArticlesBefore*Journal+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');
% VecValueTemp6=repmat('0',size(VecFigure,1),1); % Authors without any article published before the editor's appointment
% ValueTemp=find(VecFigureTemp(:,2)>=1);
% VecValueTemp6(ValueTemp,1)=repmat('1',size(ValueTemp,1),1); % Authors with articles published before the editor's appointment
% VecValueTemp4=table(VecFigureTemp(:,1),VecValueTemp,VecValueTemp6,VecFigureTemp(:,11),VecValueTemp5,'VariableNames',{'ArticlesAfter','CategoryAuthor','ArticlesBefore','Editor','Time'});
% ValueResultsModel1Temp4=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*ArticlesBefore*Time+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==2
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end

return
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('E',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==2);
VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
VecValueTemp5=repmat('C',size(VecFigure,1),1); % Editors who arrived after the launch of the editorial policy
ValueTemp=find(VecFigure(:,end)==2);
VecValueTemp5(ValueTemp,1)=repmat('D',size(ValueTemp,1),1); % Editors who arrived before the launch of the editorial policy
% VecValueTemp5=[VecValueTemp5(8:end,:);VecValueTemp5(1:7,:)]; % If commented, results are for authors who arrived before
% VecValueTemp=[VecValueTemp(8:end,:);VecValueTemp(1:7,:)]; % If commented, results are for authors who arrived before
% VecFigure=[VecFigure(8:end,:);VecFigure(1:7,:)]; % If commented, results are for authors who arrived before
% VecValueTemp5=[VecValueTemp5(39648:end,:);VecValueTemp5(1:39647,:)]; % If commented, results are for authors who arrived before
% VecValueTemp=[VecValueTemp(39648:end,:);VecValueTemp(1:39647,:)]; % If commented, results are for authors who arrived before
% VecFigure=[VecFigure(39648:end,:);VecFigure(1:39647,:)]; % If commented, results are for authors who arrived before
% Model for the analysis comparing the number of articles of former co-authors and the ther authors in the editor's journal
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel2=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],[VecValueTemp5;VecValueTemp5],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor','Time'});
ValueResultsModel2Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time+(1|Editor)','FitMethod','REML');
% ValueResultsModel2Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+CategoryAuthor*Time+CategoryArticle*Time+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],[VecValueTemp5;VecValueTemp5],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor','Time'});
ValueResultsModel2Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle*Time+(1|Editor)','FitMethod','REML');
% ValueResultsModel2Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+CategoryAuthor*Time+CategoryArticle*Time+(1|Editor)','FitMethod','REML');
VecFigureTemp=VecFigure;
ValueTemp=find(VecFigureTemp(:,1)>=1);
VecFigureTemp(ValueTemp,1)=ones(size(ValueTemp,1),1);
VecValueTemp4=table(VecFigureTemp(:,1),VecValueTemp,VecFigureTemp(:,2),VecFigureTemp(:,11),VecValueTemp5,'VariableNames',{'ArticlesAfter','CategoryAuthor','ArticlesBefore','Editor','Time'});
ValueResultsModel2Temp3=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*ArticlesBefore*Time+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResultsModel3=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable1+CategoryAuthor*Variable27+(1|Editor)','FitMethod','REML');



